package com.jzg.jcptadmin.adpter;

import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jzg.jcptadmin.R;
import com.jzg.jcptadmin.app.AppContext;
import com.jzg.jcptadmin.data.vo.ImageItem;
import com.jzg.jcptadmin.view.TouchImageView;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by jzg on 2015/12/24.
 */
public class ExtendedViewPagerAdapter extends PagerAdapter {
    private List<ImageItem>  imageList;
    private AppContext context;
    public ExtendedViewPagerAdapter(AppContext context,List<ImageItem> list) {
        this.context = context;
        this.imageList =list;
    }

    @Override
    public int getCount() {
        return imageList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.photo_item, null);
        TouchImageView imageView = (TouchImageView) view.findViewById(R.id.photo_img);
        TextView title = (TextView) view.findViewById(R.id.title);
        title.setText(imageList.get(position).getPicName());
        ImageLoader.getInstance().displayImage("file://" + imageList.get(position).getImagePath(), imageView, context.options);
        container.addView(view, RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}